package com.lun.swordtowardoffer2.c02;

public class PivotIndex {

	public int pivotIndex(int[] nums) {
		int total = 0;
		
		for(int num : nums) 
			total += num;
		
		int frontSum = 0;
		
		for(int i = 0; i < nums.length; i++) {
			int backSum = total - nums[i] - frontSum;
			
			if(frontSum == backSum)
				return i;
			frontSum += nums[i];
		}
		
		return -1;
	}	
	
}
